package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.services.HelpAndFeedbackInfo;
import com.tenglong.teacher.ui.adapter.viewholder.HelpAndFeedBackBottomViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.HelpAndFeedBackViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.List;

/**
 * @author hdx on 2019/4/8.
 */
public class MyExpandableAdapter extends RecyclerView.Adapter<BaseViewHolder<HelpAndFeedbackInfo>> {
    private List<HelpAndFeedbackInfo> infos;
    public MyExpandableAdapter(List<HelpAndFeedbackInfo> infos) {
        this.infos = infos;
    }

    @NonNull
    @Override
    public BaseViewHolder<HelpAndFeedbackInfo> onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        switch (i) {
            case 0:
                return new HelpAndFeedBackViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.help_and_feedback_item_layout, viewGroup, false));
            default:
                return new HelpAndFeedBackBottomViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.help_and_feedback_bottom_layout, viewGroup, false));
        }
    }

    @Override
    public int getItemViewType(int position) {
        return infos.get(position).isBottom ? 1 : 0;
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<HelpAndFeedbackInfo> helpAndFeedbackInfoBaseViewHolder, int i) {
        helpAndFeedbackInfoBaseViewHolder.setLayoutInfo(infos.get(i));
    }

    @Override
    public int getItemCount() {
        return infos.size();
    }
}
